package com.github.skystardust.lotteryex.gui.animation.update.imp;

import com.github.skystardust.lotteryex.gui.animation.update.AbstractAnimationRunnable;
import com.github.skystardust.lotteryex.gui.inventory.LotteryInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import java.util.Map;
import java.util.stream.Collectors;

public class AnimationRegularIncreaseRunnable extends AbstractAnimationRunnable {
    private int maxSlot;
    private int increaseSlot;
    private int minSlot;

    public AnimationRegularIncreaseRunnable(LotteryInventory lotteryInventory, Map<Integer, ItemStack> displayItemMap) {
        super(lotteryInventory, displayItemMap);
    }

    public AnimationRegularIncreaseRunnable(Map<String, Object> stringObjectMap) {
        super(stringObjectMap);
        //todo 实现AnimationRegularIncreaseRunnable反序列化
    }


    @Override
    public void run() {
        getLotteryInventory().toInventory(null).clear();
        Map<Integer, ItemStack> collect = getDisplayItemMap().entrySet()
                .stream()
                .collect(Collectors.toMap(entry -> {
                    if (entry.getKey() + getIncreaseSlot() >= getMaxSlot()) {
                        return getMinSlot();
                    }
                    return entry.getKey() + getIncreaseSlot();
                }, Map.Entry::getValue));
        collect.forEach((key, value) -> getLotteryInventory().getInventory().setItem(key, value));
        setDisplayItemMap(collect);
    }

    public int getMaxSlot() {
        return maxSlot;
    }

    public void setMaxSlot(int maxSlot) {
        this.maxSlot = maxSlot;
    }

    public int getIncreaseSlot() {
        return increaseSlot;
    }

    public void setIncreaseSlot(int increaseSlot) {
        this.increaseSlot = increaseSlot;
    }

    public int getMinSlot() {
        return minSlot;
    }

    public void setMinSlot(int minSlot) {
        this.minSlot = minSlot;
    }

    @Override
    public Map<String, Object> serialize() {
        //todo 实现序列化
        return null;
    }
}
